package com.example.meituxiuxiu.activitys;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class BroadcastTestActivity extends Activity {

    private static final  String ACTION = "com.LY.meituxiuxiu"

    private MyBroadcastReceiver broadcastReceiver;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        broadcastReceiver = new MyBroadcastReceiver();
        IntentFilter intentFilter =new IntentFilter(ACTION);
        LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver);
    }
    class MyBroadcastReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context,"ok",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }
    }
}
